<!DOCTYPE html>

<html lang="en">
  <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Class Autoloader &mdash; Phalcon 3.0.1 文档</title>
    <meta name="keywords" content="php, phalcon, phalcon php, php framework, faster php framework">
    <link rel="stylesheet" type="text/css" href="http://cdn.staticfile.org/twitter-bootstrap/3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="/www/css/phalcon.min.css" />
    <link href='//fonts.googleapis.com/css?family=Open+Sans:700,400' rel='stylesheet' type='text/css'>
    <link href="//fonts.googleapis.com/css?family=Merriweather:400,700" rel="stylesheet" type="text/css" />
    <!--
    EUROPE <link href='//fonts.googleapis.com/css?family=Open+Sans:700,400&subset=latin-ext' rel='stylesheet' type='text/css'>
    GREEK <link href='//fonts.googleapis.com/css?family=Open+Sans:700,400&subset=greek-ext' rel='stylesheet' type='text/css'>
    RUSSIA <link href='//fonts.googleapis.com/css?family=Open+Sans:700,400&subset=cyrillic-ext,latin' rel='stylesheet' type='text/css'>
    -->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <link rel="stylesheet" href="../static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../static/docs.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.0.1',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>

    <script src="http://cdn.staticfile.org/jquery/1.8.1/jquery.min.js"></script>
    <script type="text/javascript" src="../static/docs.js"></script>
    <link rel="shortcut icon" href="../static/favicon.ico"/>
    <link rel="top" title="Phalcon 3.0.1 文档" href="../index.html" />
    <link rel="next" title="日志记录（Logging）" href="logging.html" />
    <link rel="prev" title="多语言支持（Multi-lingual Support）" href="translate.html" /> 
  </head>
  <body>

<header class="page-header">
    <nav class="navbar" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu-container">
                    <span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
                </button>
                <a class="navbar-brand phalcon-logo" href="/"><span itemprop="name" class="sr-only">Phalcon PHP</span></a>
            </div>

            <div class="collapse navbar-collapse navbar-right" id="main-menu-container">
                <ul class="nav navbar-nav main-menu">
                  <li class="first"><a href="//phalconphp.com/en/download" class="header-nav-link">Download</a></li>
                  <li><a href="//docs.phalconphp.com/en/latest/index.html" class="header-nav-link" target="_blank">Documentation</a></li>
                  <li><a href="//forum.phalconphp.com/" class="header-nav-link" target="_blank">Forum</a></li>
                  <li><a href="//blog.phalconphp.com/" class="header-nav-link" target="_blank">Blog</a></li>
                  <li><a href="//phalconist.com/" class="header-nav-link" target="_blank">Resources</a></li>
                  <li><a href="//phalconphp.com/en/about">About</a></li>
                  <li><div align="right">
                      <iframe src="https://ghbtns.com/github-btn.html?user=phalcon&amp;repo=cphalcon&amp;type=watch&amp;count=true&amp;size=large"
      allowtransparency="true" frameborder="0" scrolling="0" width="152px" height="30px"></iframe>
                    </div></li>
                </ul>
            </div>
        </div>
    </nav>
  </header>

<div class="heading">
    <div class="container">
        <div class="row">
            <h2>Documentation</h2>
        </div>
    </div>
</div>
    <div class="related">
      <ul>
        <li class="right" >
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="logging.html" title="日志记录（Logging）"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="translate.html" title="多语言支持（Multi-lingual Support）"
             accesskey="P">上一页</a> |</li>
        <li><a href="//phalconphp.com">Home</a> &raquo;</li>
        <li><a href="../index.html">Phalcon 3.0.1 文档</a> &raquo;</li> 
      </ul>
    </div>  

      <table width="100%" align="center" cellpadding="0" cellspacing="0">
        <tr>
      <td class="primary-box" width="25%" valign="top">
            <div>
            <div id="searchbox" style="">
                <!--<form class="search" action="http://readthedocs.org/search/project/" method="get">
                  <input type="search" name="q" size="25" placeholder="Search">
                  <input type="submit" value="Go">
                  <input type="hidden" name="selected_facets" value="project:">
                </form>-->
                <div style="width:200px;padding:10px">
                  <gcse:searchbox-only></gcse:searchbox-only>
                </div>
            </div>
            </div>
            <div style="padding:5px;padding-left:10px">
              <div id="carbonads-container">
                <div class="carbonad"><div id="azcarbon"></div>
                <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=phalconphpcom" id="_carbonads_js"></script>
                </div></div>
            </div>
            <h3><a href="../index.html">內容目录</a></h3>
            <ul>
<li><a class="reference internal" href="#">Class Autoloader</a><ul>
<li><a class="reference internal" href="#security-layer">安全层（Security Layer）</a></li>
<li><a class="reference internal" href="#registering-namespaces">注册命名空间（Registering Namespaces）</a></li>
<li><a class="reference internal" href="#registering-prefixes">注册前缀（Registering Prefixes）</a></li>
<li><a class="reference internal" href="#registering-directories">注册文件夹（Registering Directories）</a></li>
<li><a class="reference internal" href="#registering-classes">注册类名（Registering Classes）</a></li>
<li><a class="reference internal" href="#additional-file-extensions">额外的扩展名（Additional file extensions）</a></li>
<li><a class="reference internal" href="#modifying-current-strategies">修改当前策略（Modifying current strategies）</a></li>
<li><a class="reference internal" href="#autoloading-events">自动加载事件（Autoloading Events）</a></li>
<li><a class="reference internal" href="#troubleshooting">注意事项（Troubleshooting）</a></li>
</ul>
</li>
</ul>

            <h4>上一个主题</h4>
            <p class="topless"><a href="translate.html" title="上一章">&lt; 多语言支持（Multi-lingual Support）</a></p>
            <h4>下一个主题</h4>
            <p class="topless"><a href="logging.html" title="下一章">日志记录（Logging） &gt;</a></p>
            <h3>本页</h3>
            <ul class="this-page-menu">
              <li><a href="../sources/reference/loader.md" rel="nofollow">显示源代码</a></li>
            </ul>
        </td>
          <td class="second-box" valign="top">
            <div class="document">
                <div class="documentwrapper">
                  <div class="bodywrapper">
                    <div class="body" >
                      
  <div class="section" id="class-autoloader">
<h1>Class Autoloader<a class="headerlink" href="#class-autoloader" title="永久链接至标题">¶</a></h1>
<p><a class="reference internal" href="../api/Phalcon_Loader.html"><em>Phalcon\Loader</em></a> allows you to load project classes automatically,
based on some predefined rules. Since this component is written in C, it provides the lowest overhead in
reading and interpreting external PHP files.</p>
<p>The behavior of this component is based on the PHP&#8217;s capability of <a class="reference external" href="http://www.php.net/manual/en/language.oop5.autoload.php">autoloading classes</a>. If a class that does
not yet exist is used in any part of the code, a special handler will try to load it.
<a class="reference internal" href="../api/Phalcon_Loader.html"><em>Phalcon\Loader</em></a> serves as the special handler for this operation.
By loading classes on a need-to-load basis, the overall performance is increased since the only file
reads that occur are for the files needed. This technique is called <a class="reference external" href="http://en.wikipedia.org/wiki/Lazy_initialization">lazy initialization</a>.</p>
<p>With this component you can load files from other projects or vendors, this autoloader is <a class="reference external" href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md">PSR-0</a> and <a class="reference external" href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4.md">PSR-4</a> compliant.</p>
<p><a class="reference internal" href="../api/Phalcon_Loader.html"><em>Phalcon\Loader</em></a> offers four options to autoload classes. You can use them one at a time or combine them.</p>
<div class="section" id="security-layer">
<h2>安全层（Security Layer）<a class="headerlink" href="#security-layer" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="../api/Phalcon_Loader.html"><em>Phalcon\Loader</em></a> offers a security layer sanitizing by default class names avoiding possible inclusion of unauthorized files.
Consider the following example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="c1">// Basic autoloader</span>
<span class="nb">spl_autoload_register</span><span class="p">(</span>
    <span class="k">function</span> <span class="p">(</span><span class="nv">$className</span><span class="p">)</span> <span class="p">{</span>
        <span class="nv">$filepath</span> <span class="o">=</span> <span class="nv">$className</span> <span class="o">.</span> <span class="s2">&quot;.php&quot;</span><span class="p">;</span>

        <span class="k">if</span> <span class="p">(</span><span class="nb">file_exists</span><span class="p">(</span><span class="nv">$filepath</span><span class="p">))</span> <span class="p">{</span>
            <span class="k">require</span> <span class="nv">$filepath</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="p">}</span>
<span class="p">);</span>
</pre></div>
</div>
<p>The above auto-loader lacks any kind of security. If a function mistakenly launches the auto-loader and
a malicious prepared string is used as parameter this would allow to execute any file accessible by the application:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="c1">// This variable is not filtered and comes from an insecure source</span>
<span class="nv">$className</span> <span class="o">=</span> <span class="s2">&quot;../processes/important-process&quot;</span><span class="p">;</span>

<span class="c1">// Check if the class exists triggering the auto-loader</span>
<span class="k">if</span> <span class="p">(</span><span class="nb">class_exists</span><span class="p">(</span><span class="nv">$className</span><span class="p">))</span> <span class="p">{</span>
    <span class="c1">// ...</span>
<span class="p">}</span>
</pre></div>
</div>
<p>If &#8216;../processes/important-process.php&#8217; is a valid file, an external user could execute the file without
authorization.</p>
<p>To avoid these or most sophisticated attacks, <a class="reference internal" href="../api/Phalcon_Loader.html"><em>Phalcon\Loader</em></a> removes invalid characters from the class name,
reducing the possibility of being attacked.</p>
</div>
<div class="section" id="registering-namespaces">
<h2>注册命名空间（Registering Namespaces）<a class="headerlink" href="#registering-namespaces" title="永久链接至标题">¶</a></h2>
<p>If you&#8217;re organizing your code using namespaces, or using external libraries which do, the <code class="code docutils literal"><span class="pre">registerNamespaces()</span></code> method provides the autoloading mechanism. It
takes an associative array; the keys are namespace prefixes and their values are directories where the classes are located in. The namespace
separator will be replaced by the directory separator when the loader tries to find the classes. Always remember to add a trailing slash at
the end of the paths.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Loader</span><span class="p">;</span>

<span class="c1">// Creates the autoloader</span>
<span class="nv">$loader</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Loader</span><span class="p">();</span>

<span class="c1">// Register some namespaces</span>
<span class="nv">$loader</span><span class="o">-&gt;</span><span class="na">registerNamespaces</span><span class="p">(</span>
    <span class="p">[</span>
       <span class="s2">&quot;Example\Base&quot;</span>    <span class="o">=&gt;</span> <span class="s2">&quot;vendor/example/base/&quot;</span><span class="p">,</span>
       <span class="s2">&quot;Example\Adapter&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;vendor/example/adapter/&quot;</span><span class="p">,</span>
       <span class="s2">&quot;Example&quot;</span>         <span class="o">=&gt;</span> <span class="s2">&quot;vendor/example/&quot;</span><span class="p">,</span>
    <span class="p">]</span>
<span class="p">);</span>

<span class="c1">// Register autoloader</span>
<span class="nv">$loader</span><span class="o">-&gt;</span><span class="na">register</span><span class="p">();</span>

<span class="c1">// The required class will automatically include the</span>
<span class="c1">// file vendor/example/adapter/Some.php</span>
<span class="nv">$some</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\Example\Adapter\Some</span><span class="p">();</span>
</pre></div>
</div>
</div>
<div class="section" id="registering-prefixes">
<h2>注册前缀（Registering Prefixes）<a class="headerlink" href="#registering-prefixes" title="永久链接至标题">¶</a></h2>
<p>This strategy is similar to the namespaces strategy. It takes an associative array, which keys are prefixes and their values are directories
where the classes are located in. The namespace separator and the &#8220;_&#8221; underscore character will be replaced by the directory separator when
the loader try to find the classes. Remember always to add a trailing slash at the end of the paths.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Loader</span><span class="p">;</span>

<span class="c1">// Creates the autoloader</span>
<span class="nv">$loader</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Loader</span><span class="p">();</span>

<span class="c1">// Register some prefixes</span>
<span class="nv">$loader</span><span class="o">-&gt;</span><span class="na">registerPrefixes</span><span class="p">(</span>
    <span class="p">[</span>
        <span class="s2">&quot;Example_Base&quot;</span>    <span class="o">=&gt;</span> <span class="s2">&quot;vendor/example/base/&quot;</span><span class="p">,</span>
        <span class="s2">&quot;Example_Adapter&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;vendor/example/adapter/&quot;</span><span class="p">,</span>
        <span class="s2">&quot;Example_&quot;</span>        <span class="o">=&gt;</span> <span class="s2">&quot;vendor/example/&quot;</span><span class="p">,</span>
    <span class="p">]</span>
<span class="p">);</span>

<span class="c1">// Register autoloader</span>
<span class="nv">$loader</span><span class="o">-&gt;</span><span class="na">register</span><span class="p">();</span>

<span class="c1">// The required class will automatically include the</span>
<span class="c1">// file vendor/example/adapter/Some.php</span>
<span class="nv">$some</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\Example_Adapter_Some</span><span class="p">();</span>
</pre></div>
</div>
</div>
<div class="section" id="registering-directories">
<h2>注册文件夹（Registering Directories）<a class="headerlink" href="#registering-directories" title="永久链接至标题">¶</a></h2>
<p>The third option is to register directories, in which classes could be found. This option is not recommended in terms of performance,
since Phalcon will need to perform a significant number of file stats on each folder, looking for the file with the same name as the class.
It&#8217;s important to register the directories in relevance order. Remember always add a trailing slash at the end of the paths.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Loader</span><span class="p">;</span>

<span class="c1">// Creates the autoloader</span>
<span class="nv">$loader</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Loader</span><span class="p">();</span>

<span class="c1">// Register some directories</span>
<span class="nv">$loader</span><span class="o">-&gt;</span><span class="na">registerDirs</span><span class="p">(</span>
    <span class="p">[</span>
        <span class="s2">&quot;library/MyComponent/&quot;</span><span class="p">,</span>
        <span class="s2">&quot;library/OtherComponent/Other/&quot;</span><span class="p">,</span>
        <span class="s2">&quot;vendor/example/adapters/&quot;</span><span class="p">,</span>
        <span class="s2">&quot;vendor/example/&quot;</span><span class="p">,</span>
    <span class="p">]</span>
<span class="p">);</span>

<span class="c1">// Register autoloader</span>
<span class="nv">$loader</span><span class="o">-&gt;</span><span class="na">register</span><span class="p">();</span>

<span class="c1">// The required class will automatically include the file from</span>
<span class="c1">// the first directory where it has been located</span>
<span class="c1">// i.e. library/OtherComponent/Other/Some.php</span>
<span class="nv">$some</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\Some</span><span class="p">();</span>
</pre></div>
</div>
</div>
<div class="section" id="registering-classes">
<h2>注册类名（Registering Classes）<a class="headerlink" href="#registering-classes" title="永久链接至标题">¶</a></h2>
<p>The last option is to register the class name and its path. This autoloader can be very useful when the folder convention of the
project does not allow for easy retrieval of the file using the path and the class name. This is the fastest method of autoloading.
However the more your application grows, the more classes/files need to be added to this autoloader, which will effectively make
maintenance of the class list very cumbersome and it is not recommended.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Loader</span><span class="p">;</span>

<span class="c1">// Creates the autoloader</span>
<span class="nv">$loader</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Loader</span><span class="p">();</span>

<span class="c1">// Register some classes</span>
<span class="nv">$loader</span><span class="o">-&gt;</span><span class="na">registerClasses</span><span class="p">(</span>
    <span class="p">[</span>
        <span class="s2">&quot;Some&quot;</span>         <span class="o">=&gt;</span> <span class="s2">&quot;library/OtherComponent/Other/Some.php&quot;</span><span class="p">,</span>
        <span class="s2">&quot;Example\Base&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;vendor/example/adapters/Example/BaseClass.php&quot;</span><span class="p">,</span>
    <span class="p">]</span>
<span class="p">);</span>

<span class="c1">// Register autoloader</span>
<span class="nv">$loader</span><span class="o">-&gt;</span><span class="na">register</span><span class="p">();</span>

<span class="c1">// Requiring a class will automatically include the file it references</span>
<span class="c1">// in the associative array</span>
<span class="c1">// i.e. library/OtherComponent/Other/Some.php</span>
<span class="nv">$some</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\Some</span><span class="p">();</span>
</pre></div>
</div>
</div>
<div class="section" id="additional-file-extensions">
<h2>额外的扩展名（Additional file extensions）<a class="headerlink" href="#additional-file-extensions" title="永久链接至标题">¶</a></h2>
<p>Some autoloading strategies such as  &#8220;prefixes&#8221;, &#8220;namespaces&#8221; or &#8220;directories&#8221; automatically append the &#8220;php&#8221; extension at the end of the checked file. If you
are using additional extensions you could set it with the method &#8220;setExtensions&#8221;. Files are checked in the order as it were defined:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Loader</span><span class="p">;</span>

<span class="c1">// Creates the autoloader</span>
<span class="nv">$loader</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Loader</span><span class="p">();</span>

<span class="c1">// Set file extensions to check</span>
<span class="nv">$loader</span><span class="o">-&gt;</span><span class="na">setExtensions</span><span class="p">(</span>
    <span class="p">[</span>
        <span class="s2">&quot;php&quot;</span><span class="p">,</span>
        <span class="s2">&quot;inc&quot;</span><span class="p">,</span>
        <span class="s2">&quot;phb&quot;</span><span class="p">,</span>
    <span class="p">]</span>
<span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="modifying-current-strategies">
<h2>修改当前策略（Modifying current strategies）<a class="headerlink" href="#modifying-current-strategies" title="永久链接至标题">¶</a></h2>
<p>Additional auto-loading data can be added to existing values by passing &#8220;true&#8221; as the second parameter:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="c1">// Adding more directories</span>
<span class="nv">$loader</span><span class="o">-&gt;</span><span class="na">registerDirs</span><span class="p">(</span>
    <span class="p">[</span>
        <span class="s2">&quot;../app/library/&quot;</span><span class="p">,</span>
        <span class="s2">&quot;../app/plugins/&quot;</span><span class="p">,</span>
    <span class="p">],</span>
    <span class="k">true</span>
<span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="autoloading-events">
<h2>自动加载事件（Autoloading Events）<a class="headerlink" href="#autoloading-events" title="永久链接至标题">¶</a></h2>
<p>In the following example, the EventsManager is working with the class loader, allowing us to obtain debugging information regarding the flow of operation:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Events\Event</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Events\Manager</span> <span class="k">as</span> <span class="nx">EventsManager</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Loader</span><span class="p">;</span>

<span class="nv">$eventsManager</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">EventsManager</span><span class="p">();</span>

<span class="nv">$loader</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Loader</span><span class="p">();</span>

<span class="nv">$loader</span><span class="o">-&gt;</span><span class="na">registerNamespaces</span><span class="p">(</span>
    <span class="p">[</span>
        <span class="s2">&quot;Example</span><span class="se">\\</span><span class="s2">Base&quot;</span>    <span class="o">=&gt;</span> <span class="s2">&quot;vendor/example/base/&quot;</span><span class="p">,</span>
        <span class="s2">&quot;Example</span><span class="se">\\</span><span class="s2">Adapter&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;vendor/example/adapter/&quot;</span><span class="p">,</span>
        <span class="s2">&quot;Example&quot;</span>          <span class="o">=&gt;</span> <span class="s2">&quot;vendor/example/&quot;</span><span class="p">,</span>
    <span class="p">]</span>
<span class="p">);</span>

<span class="c1">// Listen all the loader events</span>
<span class="nv">$eventsManager</span><span class="o">-&gt;</span><span class="na">attach</span><span class="p">(</span>
    <span class="s2">&quot;loader:beforeCheckPath&quot;</span><span class="p">,</span>
    <span class="k">function</span> <span class="p">(</span><span class="nx">Event</span> <span class="nv">$event</span><span class="p">,</span> <span class="nx">Loader</span> <span class="nv">$loader</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">echo</span> <span class="nv">$loader</span><span class="o">-&gt;</span><span class="na">getCheckedPath</span><span class="p">();</span>
    <span class="p">}</span>
<span class="p">);</span>

<span class="nv">$loader</span><span class="o">-&gt;</span><span class="na">setEventsManager</span><span class="p">(</span><span class="nv">$eventsManager</span><span class="p">);</span>

<span class="nv">$loader</span><span class="o">-&gt;</span><span class="na">register</span><span class="p">();</span>
</pre></div>
</div>
<p>Some events when returning boolean false could stop the active operation. The following events are supported:</p>
<table border="1" class="docutils">
<colgroup>
<col width="12%" />
<col width="38%" />
<col width="37%" />
<col width="14%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Event Name</th>
<th class="head" colspan="2">Triggered</th>
<th class="head">Can stop operation?</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>beforeCheckClass</td>
<td colspan="2">Triggered before starting the autoloading process</td>
<td>Yes</td>
</tr>
<tr class="row-odd"><td>pathFound</td>
<td colspan="2">Triggered when the loader locate a class</td>
<td>No</td>
</tr>
<tr class="row-even"><td>afterCheckClass</td>
<td colspan="2">Triggered after finish the autoloading process. If this event is launched the autoloader didn&#8217;t find the class file</td>
<td>No</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="troubleshooting">
<h2>注意事项（Troubleshooting）<a class="headerlink" href="#troubleshooting" title="永久链接至标题">¶</a></h2>
<p>Some things to keep in mind when using the universal autoloader:</p>
<ul class="simple">
<li>Auto-loading process is case-sensitive, the class will be loaded as it is written in the code</li>
<li>Strategies based on namespaces/prefixes are faster than the directories strategy</li>
<li>If a cache bytecode like <a class="reference external" href="http://php.net/manual/en/book.apc.php">APC</a> is installed this will used to retrieve the requested file (an implicit caching of the file is performed)</li>
</ul>
</div>
</div>


                    </div>
                  </div>
                </div>
            </div>
          </td>
        </tr>
      </table>
    <div class="related">
      <ul>
        <li class="right" >
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="logging.html" title="日志记录（Logging）"
             >下一页</a> |</li>
        <li class="right" >
          <a href="translate.html" title="多语言支持（Multi-lingual Support）"
             >上一页</a> |</li> 
      </ul>
    </div>

      <div class="prefooter">
  <div class="container">
      <div class="row">
          <div class="col-sm-3 text-right">
              <span>Follow along:</span>
          </div>
          <div class="col-sm-6 text-center">
              <a href="https://twitter.com/phalconphp" alt="Twitter" class="btn-social btn-social-twitter"><i class="icon-twitter"></i></a>
              <a href="https://www.facebook.com/pages/Phalcon-Framework/134230726685897" alt="Facebook" class="btn-social btn-social-facebook"><i class="icon-facebook"></i></a>
              <a href="https://plus.google.com/102376109340560896457" alt="Google+" class="btn-social btn-social-googleplus"><i class="icon-googleplus"></i></a>
              <a href="https://github.com/phalcon/cphalcon" alt="Github" class="btn-social btn-social-github"><i class="icon-github"></i></a>
          </div>
          <div class="col-sm-3">
          </div>
      </div>
  </div>

</div>
<footer class="footer">
    <div class="container">
        <div class="row">
            <div class="col-xs-4 col-sm-3">
                <h4>Download</h4>
                <ul>
                    <li><a href="/download">Installing Phalcon PHP</a></li>
                    <li><a href="http://docs.phalconphp.com/en/latest/index.html" class="header-nav-link" target="_blank">Documentation</a></li>
                    <li><a href="http://api.phalconphp.com">API</a></li>
                    <li><a href="http://docs.phalconphp.com/en/latest/reference/tutorial.html">Tutorial</a></li>
                    <li><a href="http://docs.phalconphp.com/en/latest/reference/tutorial.html#sample-applications">Sample Applications</a></li>
                </ul>
            </div>
            <div class="col-xs-4 col-sm-3">
                <h4>Community</h4>
                <ul>
                    <li><a href="http://forum.phalconphp.com/" class="header-nav-link" target="_blank">Forum</a></li>
                    <li><a href="https://github.com/phalcon/cphalcon">GitHub</a></li>
                    <li><a href="https://github.com/phalcon/cphalcon/issues">Issue Tracker</a></li>
                    <li><a href="http://stackoverflow.com/questions/tagged/phalcon">Stack Overflow</a></li>
                    <li><a href="/en/testimonials">Testimonials</a></li>
                    <li><a href="http://builtwith.phalconphp.com/">Built with Phalcon</a></li>
                    <li><a href="http://store.phalconphp.com/">Store</a></li>
                </ul>
            </div>
            <div class="col-xs-4 col-sm-2">
                <h4>About</h4>
                <ul>
                    <li><a class="link-black" href="http://blog.phalconphp.com/">Blog</a></li>
                    <li><a href="/en/about">About</a></li>
                    <li><a href="/en/team">Team</a></li>
                    <li><a href="/en/roadmap">Roadmap</a></li>
                    <li><a href="/en/donate">Donate</a></li>
                    <li><a href="/en/consulting">Consulting</a></li>
                    <li><a href="/en/hosting">Hosting</a></li>
                </ul>
            </div>
            <div id="license-spaccer" class="visible-xs"></div>
            <div id="license-wrapper" class="col-xs-12 col-sm-4">
                <p class="license">
                    Phalcon is an open-source PHP framework <br>built as a C-extension. It is available under the <br>
                    <a href="http://opensource.org/licenses/BSD-3-Clause" target="_blank">new BSD License</a>.
                    <br>
                    <br>
                    Except where otherwise noted, content on this site is licensed under the
                    <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 License.</a>
                </p>
            </div>
        </div>
    </div>
</footer>

    </div>
    <script type="text/javascript">
    $(window).on("load", function(){
      var cx = '009733439235723428699:lh9ltjgvdz8';
      var gcse = document.createElement('script');
      gcse.type = 'text/javascript';
      gcse.async = true;
      gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.google.com/cse/cse.js?cx=' + cx;
      var s = document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(gcse, s);
    });
    </script>

  </body>
</html>